﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BasePlatformCom
{
	public class ComEquipment : BaseDevice
	{
		public int atMainPort = ComMainPort.Unknown;

		public int luxValue = 0;

		public int brightValue = 0;

		// 检测附属设备（环境监测器）版本, 获取luxValue
		public string detectEqupmentVersion(SerialComPort currentComPort, int mainPort, int hubPort, int depth)
		{
			string version = "";

			bool effect = readEquMem(currentComPort, mainPort, hubPort, depth, 0, memData);
			
			if (effect == false)
			{
				return "";
			}

			for (int i = 0x40; i <= 0x46; i++)
			{
				switch (i)
				{
					case 0x40:
						version = chr(memData[i]);
						break;
					case 0x41:
						version = version + chr(memData[i]);
						break;
					case 0x42:
						version = version + memData[i];
						break;
					case 0x43:
						if (memData[i] < 10)
							version = version + "0" + memData[i];
						else
							version = version + memData[i];
						break;
					case 0x44:
						version = version + "_" + chr(memData[i]);
						break;
					case 0x45:
						if (memData[i] < 10)
							version = version + "0" + memData[i];
						else
							version = version + memData[i];
						break;
					case 0x46:
						if (memData[i] < 10)
							version = version + "_X0" + memData[i];
						else
							version = version + "_X" + memData[i];
						break;
				}
			}

			luxValue = memData[0x00000e] & 0xFF;
			luxValue |= ((memData[0x00000f] << 8) & 0xFF00);

			brightValue = memData[0x000014] & 0xFF;

			return version;
		}
	}
}
